<?php

ini_set('display_errors', 1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\advertisement\MHhzDepartment;
use Biz\model\advertisement\MPositionAdType;
use Biz\model\advertisement\MPositionProjectRelations;

$start = $argv['1'] ?? date("Y-m-d H:i:s", strtotime('-7 day'));
$end = $argv['2'] ?? date("Y-m-d H:i:s");

$list = MPositionProjectRelations::select('*', ['project_status' => 1, 'end_show_time[>]' => $start, 'end_show_time[<]' => $end, 'ORDER' => ['start_show_time']]);
if (empty($list)) exit("$start ~ $end no data");
$adConfig = MPositionAdType::select(['position_config', 'id', 'type_name']);
$adConfigMap = [];
foreach ($adConfig as $v) {
    $config = $v['position_config'] ? json_decode($v['position_config'], true) : [];
    $adConfigMap[$v['id']] = [
        'name' => $v['type_name'],
        'pos' => $config['pos'] ?? null,
    ];
}
$department = MHhzDepartment::select('*');
$department = array_column($department, 'name', 'id');
foreach ($list as $v) {
    $config = $adConfigMap[$v['ad_id']];
    $row = [
        $config['name'] ?? '',
        $config['pos'] ?? '-',
        $department[$v['department_id']] ?? '-',
        date("Y年m月d日", strtotime($v['start_show_time'])),
        date("Y年m月d日", strtotime($v['end_show_time'])),
        date("Y年m月", strtotime($v['start_show_time'])),
        $v['is_share'] == MPositionProjectRelations::SHARE_OK ? '是' : '否',
    ];
    echo implode("\t", $row), PHP_EOL;
}